﻿using AsmShaderConverter.HlslShader;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AsmShaderConverter.AsmShader
{
    public class ConstantValue : IConvertToHlsl
    {
        Register register;
        string[] values;
        readonly string originalInput;
        public Register GetDestinationRegister()
        {
            return this.register;
        }

        public ConstantValue(string line)
        {
            this.originalInput = line;
            line = line.Replace(",", ""); // Remove the comma
            var lineSplit = line.Split(' ');

            switch (lineSplit.Length)
            {
                case 6:
                    this.register = new Register(lineSplit[1], Swizzle.StandardXYZW);
                    this.values = new string[] { lineSplit[2], lineSplit[3], lineSplit[4], lineSplit[5] };
                    break;
                default:
                    throw new Exception("I thought there are everytime 4 values.");
            }
        }

        public string ToHLSL(AsmShaderFile asmShader)
        {
            return string.Format("float4 {0} = float4({1}, {2}, {3}, {4});", this.register.GetRegisterName(asmShader), values[0], values[1], values[2], values[3]);
        }

        public string ToHLSLWitchComment(AsmShaderFile asmShader)
        {
            return this.ToHLSL(asmShader) + " // " + this.originalInput;
        }
    }
}
